<!--  -->
<template>
  <div>
    <el-form :inline="true" :model="formFied" class="demo-form-inline" ref='elForm'>
      <template v-for="(item, index) in formData">
        <el-form-item :label="item.label"  :key="index" :prop='item.prop' :rules='item.rules'>
          <el-input
            v-if="item.type === 'input'"
            v-model="formFied[item.prop]"
            :placeholder="item.label"
          >
          </el-input>
          <el-select
            v-if="item.type === 'select'"
            v-model="formFied[item.prop]"
          >
           <el-option v-for='(n,i) in item.option' :label="n.label" :value="n.value" :key='i'></el-option>
          </el-select>
        </el-form-item>
      </template>
    </el-form>
    <!-- 按钮 -->
    <div v-if="btnMap.length>0" style="float:right">
      <template v-for="(btn,index) in btnMap">
        <el-button :type="btn.type" v-if="btn.key==='submit'" @click="submit">{{btn.text}}</el-button>
        <el-button :type="btn.type" v-if="btn.key==='cancel'" @click="btn.callback">{{btn.text}}</el-button>
        <el-button :type="btn.type" v-if="btn.key==='reset'" @click="reset">{{btn.text}}</el-button>
      </template>
    </div>
  </div>
</template>

<script>
import createRules from './rules/rules.js'
export default {
  props: {
    formItem: {
      type: Array,
      default: () => []
    },
    formFied: {
      type: Object,
      default: () => {}
    },
    btnMap: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      formData: []
    };
  },

  components: {},
  beforeMount(){
    this.formData = createRules(this.formItem)
    console.log('formData=', this.formData);
    console.log('btnMap=', this.btnMap);
  },
  mounted(){
    
  },
  computed: {},

  methods: {
    submit(){
      console.log('提交')
    },
    reset(){
      console.log('重置')
      this.$refs.elForm.resetFields()
    },
    cancel(){
      console.log('取消')
    }
  },
};
</script>
<style lang='less' scoped>
</style>